import '../manger/network_utils.dart';
import '../models/message_model.dart';

class LoadMessageInfoResult {
  final bool success;
  final List<MsgOrderModel>? msgListModel;

  LoadMessageInfoResult({required this.success, this.msgListModel});
}

class MeassageInfoManager {
  static final MeassageInfoManager _instance = MeassageInfoManager._internal();
  factory MeassageInfoManager() => _instance;
  MeassageInfoManager._internal();

  // 存储数据
  List<MsgOrderModel>? _msgListModel;

  List<MsgOrderModel>? get msgInfoModel => _msgListModel;

  // 加载数据
  Future<LoadMessageInfoResult> loadInfoData() async {
    try {
      final response = await NetworkUtils.get(
        RequestCmd.msgList, // 保持原有的请求命令
      );

      final model = MsgModel.fromJson(response);

      if (model.code == 200) {
        _msgListModel = model.msgList;

        return LoadMessageInfoResult(success: true, msgListModel: model.msgList);
      } else {
        return LoadMessageInfoResult(success: false);
      }
      } catch (e) {
        return LoadMessageInfoResult(success: false);
      }
  }
}
